package com.test.clyq.action;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;

import com.cplatform.util2.FileTools;
import com.taobao.api.ApiException;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.domain.ItemImg;
import com.taobao.api.domain.TaobaokeItem;
import com.taobao.api.request.ItemGetRequest;
import com.taobao.api.request.TaobaokeItemsConvertRequest;
import com.taobao.api.response.ItemGetResponse;
import com.taobao.api.response.TaobaokeItemsConvertResponse;
import com.test.Constants;
import com.test.clyq.entity.EntityItem;
import com.test.clyq.entity.Users;
import com.test.clyq.form.EntityItemForm;
import com.test.clyq.service.CategoryService;
import com.test.clyq.service.EntityItemService;
import com.test.json.JsonUtil;
import com.test.util.DateUtils;
import com.test.util.FileUtils;
import com.test.util.FormatExceptionStack;
import com.test.util.Pagination;
import com.test.util.SessionUtil;
import com.test.util.StringUtils;
import com.test.webapp.action.BaseAction;

/**
 * EntityItemAction. <br>
 * 内容管理.
 * <p>
 * Copyright: Copyright (c) 2010-4-17 下午03:49:58
 * <p>
 * Company: 北京宽连十方数字技术有限公司
 * <p>
 * Author: liuxl@c-platform.com
 * <p>
 * Version: 1.0
 * <p>
 */
public class EntityItemAction extends BaseAction {

	/**
	 * 删除内容状态设置
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	public ActionForward delEntityItem(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
	        throws IOException {
		this.log.info("删除内容状态设置start");
		String entityId = request.getParameter("entityId");
		EntityItemService entityItemService = (EntityItemService) getBean("entityItemService");
		CategoryService categoryService = (CategoryService) getBean("categoryService");
		Users user = SessionUtil.getUserFromSession(request);
		try {
			EntityItem entityItem = entityItemService.getEntityItemById(Long.valueOf(entityId));
			if (Long.valueOf(1).equals(entityItem.getEntityStatus())) {
				entityItem.setEntityStatus(new Long(0));
			} else {
				entityItem.setEntityStatus(new Long(1));
			}

			entityItemService.saveOrUpdate(entityItem, user);

			this.log.debug("删除内容状态设置成功");
			this.log.info("删除内容状态设置end");
			print(response, true);
		}
		catch (Exception e) {
			this.log.error("删除内容状态设置:失败 " + FormatExceptionStack.formatException(e));
			print(response, false);
		}
		return null;
	}

	/**
	 * 彻底删除内容
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	public ActionForward delTrueEntityItem(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
	        throws IOException {
		this.log.info("删除内容start");
		String uId = request.getParameter("entityId");
		EntityItemService entityItemService = (EntityItemService) getBean("entityItemService");
		Users user = SessionUtil.getUserFromSession(request);
		StringBuilder sb = new StringBuilder();
		try {
			boolean bl = entityItemService.delEntityItemById(Long.valueOf(uId), user);
			sb.append("{");
			if (bl) {
				sb.append("success:true");
			} else {
				sb.append("error:error");
			}
			sb.append("}");
			String dd = sb.toString();
			this.log.debug("删除内容成功");
			this.log.info("删除内容end");
			print(response, dd, null, null);
		}
		catch (Exception e) {
			this.log.error("删除内容:失败 " + FormatExceptionStack.formatException(e));
			print(response, false);
		}
		return null;
	}

	/**
	 * 修改内容
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	public ActionForward editEntityItemByArticle(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
	        throws IOException {
		this.log.info("修改内容start");
		EntityItemService entityItemService = (EntityItemService) getBean("entityItemService");
		String entityId = request.getParameter("uId");
		try {
			EntityItem entityItem = entityItemService.getEntityItemById(Long.valueOf(entityId));
			// 高亮敏感词
			this.log.debug("修改内容成功");
			this.log.info("修改内容end");
			String fragStr = "{results:[{" + entityItem.toJSON() + "}]}";
			print(response, fragStr, null, null);
		}
		catch (Exception e) {
			this.log.error("修改内容:失败 " + FormatExceptionStack.formatException(e));
			print(response, false);
		}
		return null;
	}

	/**
	 * 根据一级栏目ID获得所有二级栏目的置顶内容信息列表（分页使用）
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	public ActionForward entityItemListByParentCategoryId(ActionMapping mapping, ActionForm form, HttpServletRequest request,
	        HttpServletResponse response) throws IOException {
		this.log.info("根据一级栏目ID获得所有二级栏目的置顶内容信息列表start");
		EntityItemService entityItemService = (EntityItemService) getBean("entityItemService");
		String categoryId = getParameter(request, "categoryId");
		String key = getParameter(request, "key");
		String title = getParameter(request, "title");
		try {
			String start = request.getParameter("start");
			String limit = request.getParameter("limit");
			int currpageNo = 1;
			int pageCount = 20;
			if (limit != null && !"".equals(limit)) {
				pageCount = Integer.parseInt(limit);
			}
			if (Integer.parseInt(start) / pageCount != 0) {
				currpageNo = Integer.parseInt(start) / pageCount + 1;// 当前页码
			}
			// 添加排序条件
			List<String> where = new ArrayList<String>();
			List<String> order = new ArrayList<String>();
			if ("wapfirstpage".equals(key)) {
				// 通过标题查询
				if (!StringUtils.isEmpty(title)) {
					where.add("entityitem.entityName like '%" + title + "%'");
				}
				where.add("(entityitem.isTop=1 or entityitem.wapFirstPage=1)");
				order.add("entityitem.wapFirstPage desc");
				order.add("entityitem.wapFirstPageWeight desc");
				order.add("entityitem.id desc");
			}
			Pagination pagination = new Pagination(currpageNo, pageCount);// 设置分页参数（页码和每页显示记录条数）
			List<EntityItem> list = null;
			int totalCount = 0;
			list = entityItemService.getEntityItemListByParentCategoryId(Long.valueOf(categoryId), pagination, where, order); // 获取内容列表
			totalCount = pagination.getTotalRows();
			String jsonStr = JsonUtil.getJsonStr(list, new String[] { "entityItemId", "entityName", "entityArticleModifytime",
			        "entityArticleKeyword", "isTop", "ipadOrder", "ipadShowLocation", "isFirst", "categoryWeight", "wapFirstPage",
			        "wapFirstPageWeight", "copyCount", "mmsWeight", "mmsFirstOne" }, totalCount);
			this.log.debug("根据一级栏目ID获得所有二级栏目的置顶内容信息列表成功");
			this.log.info("根据一级栏目ID获得所有二级栏目的置顶内容信息列表end");
			print(response, jsonStr, null, null);
		}
		catch (Exception e) {
			this.log.error("根据一级栏目ID获得所有二级栏目的置顶内容信息列表:失败 " + FormatExceptionStack.formatException(e));
			print(response, false);
		}
		return null;
	}

	/**
	 * 获得登录用户的回收站列表
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return 内容列表
	 * @throws IOException
	 */
	public ActionForward entityItemArticleList(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
	        throws IOException {
		this.log.info("获得列表start");
		EntityItemService entityItemService = (EntityItemService) getBean("entityItemService");
		String categoryId = request.getParameter("categoryId");
		String key = getParameter(request, "key");
		String title = getParameter(request, "title");
		try {
			String start = request.getParameter("start");
			String limit = request.getParameter("limit");
			int currpageNo = 1;
			int pageCount = 20;
			if (!StringUtils.isEmpty(limit)) {
				pageCount = Integer.parseInt(limit);
			}
			if (Integer.parseInt(start) / pageCount != 0) {
				currpageNo = Integer.parseInt(start) / pageCount + 1;// 当前页码
			}
			Pagination pagination = new Pagination(currpageNo, pageCount);// 设置分页参数（页码和每页显示记录条数）
			List<EntityItem> list = null;
			int totalCount = 0;
			// 添加查询条件和排序条件
			List<String> where = new ArrayList<String>();
			List<String> order = new ArrayList<String>();
			// 通过标题查询
			if (!StringUtils.isEmpty(title)) {
				where.add("entityitem.entityName like '%" + title + "%'");
			}
			if ("entityitem".equals(key)) {
				// order.add("entityitem.isTop desc");
				// order.add("entityitem.id desc");
				// order.add("entityitem.categoryWeight desc");
				order.add("entityitem.entityCreatetime desc");
			}

			list = entityItemService.getEntityItemListByCategoryId(Long.valueOf(categoryId), pagination, where, order); // 获取内容列表
			totalCount = pagination.getTotalRows();

			String jsonStr = JsonUtil.getJsonStr(list, new String[] { "entityItemId", "entityName", "entityTaoBaoId", "price", "entityCreatetime",
			        "convertUrl" }, totalCount);
			this.log.debug("获得内容列表成功");
			this.log.info("获得内容列表end");
			print(response, jsonStr, null, null);
		}
		catch (Exception e) {
			this.log.error("获得内容:失败 " + FormatExceptionStack.formatException(e));
			print(response, false);
		}
		return null;
	}

	/**
	 * 获得登录用户的回收站内容列表
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return 内容列表
	 * @throws IOException
	 */
	public ActionForward entityItemRecycleList(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
	        throws IOException {
		this.log.info("获得回收站列表start");
		EntityItemService entityItemService = (EntityItemService) getBean("entityItemService");
		try {
			String start = request.getParameter("start");
			int currpageNo = 1;

			if (Integer.parseInt(start) / 20 != 0) {
				currpageNo = Integer.parseInt(start) / 20 + 1;// 当前页码

			}

			Pagination pagination = new Pagination(currpageNo, 20);// 设置分页参数（页码和每页显示记录条数）

			List<EntityItem> list = null;
			int totalCount = 0;

			list = entityItemService.getRecycleBinListByWebsiteId(pagination); // 获取内容列表
			totalCount = pagination.getTotalRows();

			String jsonStr = JsonUtil
			        .getJsonStr(list, new String[] { "entityItemId", "entityName", "entityCreatetime", "entityArticleKeyword", "isTop", "isFirst",
			                "categoryWeight", "wapFirstPage", "wapFirstPageWeight", "copyCount", "mmsWeight", "mmsFirstOne" }, totalCount);
			response.setCharacterEncoding("UTF-8");
			response.setContentType("text/html; charset=utf-8");
			PrintWriter out = response.getWriter();
			out.print(jsonStr);
			// System.err.println(jsonStr);
			this.log.debug("获得回收站列表成功");
			this.log.info("获得回收站列表end");
			return null;
		}
		catch (Exception e) {
			this.log.error("获得回收站:失败 " + FormatExceptionStack.formatException(e));
			// request.setAttribute("HtmlError", "对不起，系统服务器忙，请您稍候再试.");
			return null;
		}
	}

	/**
	 * 保存内容
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	public ActionForward saveEntityItemByArticle(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
	        throws IOException {

		EntityItemForm entityItemForm = (EntityItemForm) form;

		EntityItemService entityItemService = (EntityItemService) getBean("entityItemService");
		Users user = SessionUtil.getUserFromSession(request);
		String categoryId = request.getParameter("categoryId");
		String dir = (String) Constants.settings.get("WEB_BASE_PATH");
		dir = dir.substring(0, dir.length() - 1);

		try {
			// 单条保存
			if (entityItemForm.getEntityTaoBaoId() != null && !"".equals(entityItemForm.getEntityTaoBaoId())) {
				EntityItem entityItem = new EntityItem();
				BeanUtils.copyProperties(entityItem, entityItemForm); // 复制到的对象,被复制的对象
				// 商品编号
				entityItem.setEntityTaoBaoId(entityItemForm.getEntityTaoBaoId());
				entityItem.setEntityStatus(new Long(1));
				entityItem.setEntityCategoryId(Long.parseLong(categoryId));
				entityItem.setEntityCreatetime(DateUtils.getDateTime("yyyyMMddHHmmss", new Date()));
				entityItemService.saveOrUpdate(entityItem, user);

			}

			// 批量导入数据
			if (entityItemForm.getFile() != null && entityItemForm.getFile().getFileName() != null) {
				File file = new File(dir);

				if (!file.exists()) {
					file.mkdirs();
				}
				file = null;
				String fileType = entityItemForm.getFile().getFileName().substring(entityItemForm.getFile().getFileName().lastIndexOf(".") + 1,
				                                                                   entityItemForm.getFile().getFileName().length());

				String file_name = System.currentTimeMillis() + "." + fileType;

				file = new File(dir + file_name);
				InputStream streamIn = entityItemForm.getFile().getInputStream();
				FileOutputStream streamOut = new FileOutputStream(file);
				int bytesRead = 0;

				byte[] buffer = new byte[8192];

				while ((bytesRead = streamIn.read(buffer, 0, 8192)) != -1) {
					streamOut.write(buffer, 0, bytesRead);
				}
				streamOut.close();
				streamIn.close();
				entityItemForm.getFile().destroy();
				// 文本导入
				List<String> list = FileTools.readLines(file, "GBK");
				// 批量插入数据
				if (list != null && !list.isEmpty()) {
					List eList = new ArrayList();
					for (String line : list) {
						if (!"".equals(line) && line != null) {
							EntityItem newEntity = new EntityItem();
							newEntity.setEntityTaoBaoId(line);
							newEntity.setEntityCategoryId(Long.parseLong(categoryId));
							newEntity.setEntityCreatetime(DateUtils.getDateTime("yyyyMMddHHmmss", new Date()));
							eList.add(newEntity);
						}

					}
					entityItemService.addBAtch(eList, user);
				}

			}

			this.log.debug("保存内容成功");
			this.log.info("保存内容end");
			print(response, true);
		}
		catch (Exception e) {
			this.log.error("保存内容:失败 " + FormatExceptionStack.formatException(e));
			print(response, false);
		}
		return null;
	}

	/**
	 * 上传图片
	 * 
	 * @param fileForm
	 * @param request
	 * @return
	 */

	public String saveObject(FormFile file) {
		if (file == null || file.getFileName() == null || file.getFileName().equals("")) {
			return null;
		} else {
			String dir = (String) Constants.settings.get("WEB_BASE_PATH") + "upload";
			String path;
			try {
				// 调用图片的上传的方法,并且返回上传服务器的路径
				path = FileUtils.upload(dir, file);
				// path = "upload/" + path;
				// System.out.println(path);
				return path;
			}
			catch (Exception e) {
				e.printStackTrace();
				return null;
			}
		}
	}

	/**
	 * 上传图片
	 * 
	 * @param fileForm
	 * @param request
	 * @return
	 */
	public String savePic(FormFile file) {
		if (file == null) {
			return null;
		} else {
			String dir = (String) Constants.settings.get("WEB_BASE_PATH") + "/upload";
			String imageType[] = { "jpeg", "gif", "bmp", "BMP", "png", "jpg", "JPG", "GIF" };
			String fileName = file.getFileName();
			int ff = fileName.indexOf(".");
			String contentType = fileName.substring(ff + 1);
			String fileType = contentType;
			for (int j = 0; j < imageType.length; j++) {
				if (imageType[j].equals(fileType)) {
					String path;
					try {
						// 调用图片的上传的方法,并且返回上传服务器的路径
						path = FileUtils.upload(dir, file);
						return path;
					}
					catch (Exception e) {
						e.printStackTrace();
						return null;
					}
				}
			}
		}
		return null;
	}

	/**
	 * 根据 关键词 获取 内容列表
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return 内容列表
	 * @throws IOException
	 */
	public ActionForward searchArticleList(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
	        throws IOException {
		this.log.info("获得列表start");
		EntityItemService entityItemService = (EntityItemService) getBean("entityItemService");
		String keyword = request.getParameter("keyword");
		try {
			int totalCount = 0;
			String start = request.getParameter("start");
			String limit = request.getParameter("limit");
			int currpageNo = 1;
			int pageCount = 20;
			if (limit != null && !"".equals(limit)) {
				pageCount = Integer.parseInt(limit);
			}
			if (Integer.parseInt(start) / pageCount != 0) {
				currpageNo = Integer.parseInt(start) / pageCount + 1;// 当前页码
			}
			Pagination pagination = new Pagination(currpageNo, pageCount);// 设置分页参数（页码和每页显示记录条数）
			List<EntityItem> list = entityItemService.getEntityItemListByKeyWord(keyword, pagination);
			totalCount = pagination.getTotalRows();
			String jsonStr = JsonUtil.getJsonStr(list, new String[] { "entityItemId", "entityName", "entityArticleModifytime",
			        "entityArticleKeyword", "isTop", "isFirst" }, totalCount);
			this.log.debug("获得内容列表成功");
			this.log.info("获得内容列表end");
			print(response, jsonStr, null, null);
		}
		catch (Exception e) {
			this.log.error("获得内容:失败 " + FormatExceptionStack.formatException(e));
			print(response, false);
		}
		return null;
	}

	/**
	 * 更新内容
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	public ActionForward updateEntityItemByArticle(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
	        throws IOException {
		this.log.info("更新内容start");
		EntityItemForm entityItemForm = (EntityItemForm) form;
		EntityItemService entityItemService = (EntityItemService) getBean("entityItemService");
		Users user = SessionUtil.getUserFromSession(request);
		try {

			EntityItem entityItem = entityItemService.getEntityItemById(entityItemForm.getEntityItemId());
			if (entityItem != null) {

				entityItem.setEntityContent(entityItemForm.getEntityContent());
				// entityItem.setEntityDesc(entityItemForm.getEntityDesc());
				entityItem.setEntityName(entityItemForm.getEntityName());

				entityItemService.saveOrUpdate(entityItem, user);
			}
			this.log.debug("更新内容成功");
			this.log.info("更新内容end");
			print(response, true);
		}
		catch (Exception e) {
			this.log.error("保存内容:失败 " + FormatExceptionStack.formatException(e));
			print(response, false);
		}
		return null;
	}

	/**
	 * 调用淘宝接口获取商品数据
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	public ActionForward getTaoBaoInfo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
	        throws IOException {
		this.log.info("调用淘宝接口获取商品数据  start...");
		EntityItemService entityItemService = (EntityItemService) getBean("entityItemService");
		Users user = SessionUtil.getUserFromSession(request);
		String entityIdStr = getParameter(request, "entityId");
		try {

			EntityItem entityItem = entityItemService.getEntityItemById(Long.valueOf(entityIdStr));

			if (entityItem != null) {

				// String sessionKey =null;
				// //如果sessionKey 不为空，调用商品接口获取数据
				// if(SessionUtil.getKey2Session(request)!=null &&
				// !"".equals(SessionUtil.getKey2Session(request))){
				// log.error("sessionKey is not null ...");
				// sessionKey = SessionUtil.getKey2Session(request);
				//					
				// }else{
				// log.error("sessionKey is null ...");
				// log.error("getSessionKey start ...");
				// TaoBaoUtil.getResult((String)
				// Constants.settings.get("SESSION_KEY")+(String)
				// Constants.settings.get("APP_KEY"), null);
				// System.err.println("sessionUrl====="+(String)
				// Constants.settings.get("SESSION_KEY")+(String)
				// Constants.settings.get("APP_KEY"));
				// sessionKey = SessionUtil.getKey2Session(request);
				// log.error("getSessionKey end ...");
				// }
				//
				// log.error("sessionKey ====="+sessionKey);

				TaobaoClient client = new DefaultTaobaoClient((String) Constants.settings.get("TAOBAO_URL"), (String) Constants.settings
				        .get("APP_KEY"), (String) Constants.settings.get("APP_SECRET"));// 实例化TopClient类

				ItemGetRequest req = new ItemGetRequest();
				req.setFields("detail_url,title,desc,pic_url,price,item_img");
				req.setNumIid(Long.valueOf(entityItem.getEntityTaoBaoId()));
				try {
					ItemGetResponse iResponse = client.execute(req, "");

					entityItem.setEntityName(iResponse.getItem().getTitle());
					entityItem.setDetailUrl(iResponse.getItem().getDetailUrl());
					entityItem.setEntityImgUrl(iResponse.getItem().getPicUrl());
					entityItem.setPrice(iResponse.getItem().getPrice());
					entityItem.setEntityContent(iResponse.getItem().getDesc());
					// System.err.println(iResponse.getItem().getItemImgs());
					// System.err.println(iResponse.getBody());
					System.err.println(iResponse.getItem().getTitle());

					String imgs = "";
					for (ItemImg img : iResponse.getItem().getItemImgs()) {

						imgs += img.getUrl() + ",";
					}
					entityItem.setEntityImgs(imgs);

				}
				catch (ApiException e) {
					e.printStackTrace();
				}

				entityItemService.saveOrUpdate(entityItem, user);

				this.log.debug("更新内容成功");
				this.log.info("更新内容end");

			}

			print(response, true);
		}
		catch (Exception e) {
			this.log.error("保存内容:失败 " + FormatExceptionStack.formatException(e));
			print(response, false);
		}
		return null;
	}

	/**
	 * 调用淘宝接口获取推广地址
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	public ActionForward getTaoBaoConvertUrl(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
	        throws IOException {
		this.log.info("调用淘宝接口获取推广地址  start...");
		EntityItemService entityItemService = (EntityItemService) getBean("entityItemService");
		Users user = SessionUtil.getUserFromSession(request);
		String entityIdStr = getParameter(request, "entityTaoBaoId");
		try {

			// EntityItem entityItem =
			// entityItemService.getEntityItemById(Long.valueOf(entityIdStr));

			if (entityIdStr != null && !"".equals(entityIdStr)) {

				System.err.println("entityTaoBaoIds========" + entityIdStr);
				TaobaoClient client = new DefaultTaobaoClient((String) Constants.settings.get("TAOBAO_URL"), (String) Constants.settings
				        .get("APP_KEY"), (String) Constants.settings.get("APP_SECRET"));// 实例化TopClient类

				TaobaokeItemsConvertRequest req = new TaobaokeItemsConvertRequest();
				req.setFields("num_iid,click_url,iid,commission,commission_rate,commission_num,commission_volume");
				req.setNick("lxl_it");
				// req.setOuterCode("bbs");
				req.setNumIids(entityIdStr);
				// req.setPid(123456L);
				req.setIsMobile(true);
				try {
					TaobaokeItemsConvertResponse taobaors = client.execute(req);

					System.err.println("sumCount=====" + taobaors.getTotalResults());

					if (taobaors.getTaobaokeItems() != null && !taobaors.getTaobaokeItems().isEmpty()) {
						for (TaobaokeItem keItem : taobaors.getTaobaokeItems()) {
							System.err.println("taobaoId-------" + keItem.getNumIid());
							EntityItem entityItem = entityItemService.getEntityItemByTaoBaoId(keItem.getNumIid().toString());
							if (entityItem != null) {
								System.err.println("url===" + keItem.getClickUrl());
								entityItem.setConvertUrl(keItem.getClickUrl());
								entityItemService.saveOrUpdate(entityItem, null);
							}

						}
					}

				}
				catch (ApiException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

				this.log.debug("更新内容成功");
				this.log.info("更新内容end");

			}

			print(response, true);
		}
		catch (Exception e) {
			this.log.error("保存内容:失败 " + FormatExceptionStack.formatException(e));
			print(response, false);
		}
		return null;
	}

}
